import React, { Suspense } from "react";
import { Card, Tabs, Tooltip } from "antd";
import { connect } from "dva";
import RobotSetUp from "@/pages/Account/robotSetup/index";
import BackRouter from "./backRouter";
import AccessSettings from "@/pages/Account/accessSettings/index";
import KnowledgeConfiguration from ".AppearanceSettings/KnowledgeConfiguration";
import HotConfiguration from ".AppearanceSettings/hotSpots";
import QuickEntry from "./quickEntry";
import BottomLabel from "./bottomLabel";
// import AppearanceSettings from "./AppearanceSettings";
import AppearanceSettings from "./appearanceSettings/index";
import TicketConfiguration from "./ticketConfiguration/index";
import ChannnelSettingMenu from "./channelSetting/menu";
import styles from "./robotEdit.less";
import BasicSetting from "./basicSetting";
import InlineSetting from "./inlineSetting";
import RobotSetting from "./robotSetting/index";
import Transfer from "./transfer";
import TerminalList from "./terminalList";
import ModelList from "@/pages/LargeModelCenter/LanguageModel/InRobot/list";
import InstructList from "./instructList";
import UserSession from "@/UserSession";
import UserProfile from "../UserProfile";
import { getInteractCenterInfo } from "@/services/robotManagement";

const { TabPane } = Tabs;

class RobotDefault extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            type: "1",
            channel: "web",
            interactCenterInfo: {
                platform: "SYS_WEB",
                id: "1769903428022177792",
                applicationId: "1769903428022177792",
                loginType: 0,
                isllmCustom: 1,
            }
        };
    }

    componentDidMount() {
        this._init_();
    }

    _init_ = async () => {
        const { dispatch } = this.props;
        let res = await getInteractCenterInfo();
        console.log(res);
        this.setState({
            interactCenterInfo: {
                id: res.id,
                platform: res.applicationPlatform,
                applicationId: res.id,
                isllmCustom: res.type,
                loginType: res.loginType,
            }
        }, () => {
            dispatch({
                type: "global/changeLayoutCollapsed",
                payload: true,
            });
        });
    }

    changeTab = (key) => {
        this.setState({ type: key }, () => {
            switch (key) {
                case "2":
                    this.AppearanceSettings.getInfo();
                    break;
                case "4":
                    this.KnowledgeConfiguration.getKnowledgeList();
                    break;
                case "8":
                    this.TicketConfiguration.getTicketList()
                    break;
                case "9":
                    this.TerminalList.getList();
                    break;
                case "10":
                    this.ModelList.getList();
                    break;
                case "11":
                    this.InstructList.getList();
                    break;
            }
        });
    };

    handleClick = (e) => {
        this.setState({ channel: e.key });
    };

    renderMenuText = (title) => {
        return <div style={{ width: 200, textAlign: "left" }}>{title}</div>;
    };

    render() {
        const { query } = this.props.location;
        const { type, channel, interactCenterInfo: { id, platform, applicationId, isllmCustom, loginType, } } = this.state;

        return (
            <Card className={styles.editCard} bordered={false} style={{ height: '100%' }} bodyStyle={{ height: '100%' }}>
                {type != 10 ? (
                    <div style={{ position: "absolute", right: 20, top: 16, zIndex: 2 }}>
                        <BackRouter pathname='/digitalEmployees'></BackRouter>
                    </div>
                ) : null}
                <Tabs activeKey={type} className={styles.robotSetMenu} onChange={this.changeTab} tabPosition={"left"} style={{ height: '100%' }}>
                    <TabPane tab={this.renderMenuText("应用设置")} disabled key='0'></TabPane>
                    <TabPane tab={this.renderMenuText("基础设置")} key='1'>
                        <div className={styles.title}>
                            <span>基础设置</span>
                        </div>
                        <BasicSetting robotId={id} channel={platform} applicationId={applicationId} />
                    </TabPane>
                    <TabPane tab={this.renderMenuText("知识设置")} key='4'>
                        <div className={styles.title}>
                            <span>知识设置</span>
                        </div>
                        <KnowledgeConfiguration
                            robotId={id}
                            onRef={(ref) => (this.KnowledgeConfiguration = ref)}
                            applicationId={applicationId}
                        />
                    </TabPane>
                    {platform != 'DIGITAL_SCREEN' ? (
                        <TabPane tab={this.renderMenuText("进线设置")} key="01">
                            <div className={styles.title}>
                                <span>进线设置</span>
                            </div>
                            <InlineSetting channel={platform} isllmCustom={isllmCustom} applicationId={applicationId} loginType={loginType} />
                        </TabPane>
                    ) : null}
                    <TabPane tab={this.renderMenuText("机器人设置")} key="02">
                        <div className={styles.title}>
                            <span>机器人设置</span>
                        </div>
                        <RobotSetting robotId={id} channel={platform} applicationId={applicationId} />
                    </TabPane>
                    {platform == 'DIGITAL_SCREEN' ? (
                        <TabPane tab={this.renderMenuText("终端管理")} key='9'>
                            <div className={styles.title}>
                                <span>终端管理</span>
                            </div>
                            <TerminalList robotId={id} applicationId={applicationId} onRef={ref => this.TerminalList = ref} />
                        </TabPane>
                    ) : null}
                    {isllmCustom == 1 ? (
                        <TabPane tab={this.renderMenuText("指令配置")} key='11'>
                            <InstructList applicationId={applicationId} onRef={ref => this.InstructList = ref} />
                        </TabPane>
                    ) : null}
                    {UserSession.hasLargeLanguage() ? (
                        <TabPane tab={this.renderMenuText("大语言模型配置")} key='10'>
                            <ModelList applicationId={applicationId} onRef={ref => this.ModelList = ref} />
                        </TabPane>
                    ) : null}
                    {loginType == 1 ? (
                        <TabPane tab={this.renderMenuText("用户配置")} key='12'>
                            <div className={styles.title}>
                                <span>用户配置</span>
                            </div>
                            <UserProfile applicationId={applicationId} />
                        </TabPane>
                    ) : null}
                </Tabs>
            </Card>
        );
    }
}

export default connect()(RobotDefault);
